<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
*/
/** 
 * Change a post's tag
 * 
 * @package Xaraya eXtensible Management System
 * @copyright (C) 2005 by the Xaraya Development Team.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.org
 *
*/

/**
 * @author John Cox
 * @author jojodee
 * add new forum topic
 */

function conversations_user_set_sub()
{

    if (!xarVarFetch('tagid', 'int:0:', $tagid, '', XARVAR_DONT_SET)) return;
    
    $uid = xarUserGetVar('uid');
    
    // This should be relatively simple.  
    
    //return var_export($tagid);
    
    // Need to think about the level for this.  Currently for posters only
    if (!xarSecurityCheck('Postcon', 1)) return;

    // OK, at this point we just need to know if they are subscribed already
    // If so, delete the subscription
    // If not, add it.
    // Then just return the appropriate icon.
    
    $subs = xarModAPIFunc('conversations', 'user', 'getsubs', array(
                                                  'tagid'   => $tagid,
                                                  'uid'     => $uid));
                                                  
    if (empty($subs)){
      // Add Subs
        xarModAPIFunc('conversations', 'user', 'createsubs', array(
                                                  'tagid'   => $tagid,
                                                  'uid'     => $uid));
      // Let's give a bonus to the tag
        xarModAPIFunc('conversations', 'user', 'updatetag', array(
                                                          'tagid'   => $tagid,
                                                          'count'   => 20));
        $data = xarTplModule('conversations', 'user', 'sub_image', 
                array('on' => true));                                                  
        // Return the image
        return $data;
    } else {
      // Delete Subs
        xarModAPIFunc('conversations', 'user', 'deletesubs', array(
                                                  'tagid'   => $tagid,
                                                  'uid'     => $uid));
      // Let's give a penalty to the tag
        xarModAPIFunc('conversations', 'user', 'updatetag', array(
                                                          'tagid'   => $tagid,
                                                          'count'   => -20));
        $data = xarTplModule('conversations', 'user', 'sub_image');                                                  
        // Return the image
        return $data;
    }
      
}

?>